home *** CD-ROM | disk | FTP | other *** search
- {
- TPTALK is a simple program that demonstrates the STHING unit.
- If you specify the name of an ASCII text file on the command line when you
- call TPTALK, it will read the file for you. If don't specify a file name,
- you can enter text and TPTALK will speak each line as you enter it.
-
- In general, TPTALK does the same thing as the TALK program supplied with the
- Speech Thing. It accepts the following command line options:
-
- /? show a list of options
- /T n specify tone (0 or 1)
- /I n specify pitch (0..9)
- /S n specify speed (0..9)
- /V n specify volume (0..9)
- /L n specify LPT port (1..3)
-
- Unlike TALK, TPTALK won't load the SPEECHVx program if it isn't already
- loaded. Note that TPTALK needs only SPEECHV2 or SPEECHV3; it is *not*
- necessary to load STALK.
-
- Written 10/90 by Kim Kokkonen, TurboPower Software
- Copyright (C) 1990, TurboPower Software. All rights reserved.
- }
-
- {$S-,I-,R-,V-,F-}
- {$M 8192,0,655360}
-
- program TpTalk;
-
- uses
- sthing;
-
- const
- modulename : string[6] = 'TPTALK';
- version = '1.00';
-
- {default values for speech parameters}
- tone : word = 5;
- volume : word = 5;
- pitch : word = 5;
- speed : word = 5;
- lpt : word = 1;
-
- var
- {file to speak}
- filename : string[79];
-
- procedure analyzecommandline;
- var
- i : word;
- arg : string[127];
-
- procedure writehelp;
- begin
- writeln('Usage:');
- writeln(' TPTALK [options] [filename]');
- writeln('Command line options:');
- writeln(' /I n specify pitch (0..9)');
- writeln(' /L n specify LPT port (1..3)');
- writeln(' /S n specify speed (0..9)');
- writeln(' /T n specify tone (0 or 1)');
- writeln(' /V n specify volume (0..9)');
- halt;
- end;
-
- procedure invalidoption;
- begin
- writeln('Invalid command line option: ', arg);
- writehelp;
- end;
-
- function stupcase(s : string) : string;
- var
- p : word;
- begin
- stupcase[0] := s[0];
- for p := 1 to length(s) do
- stupcase[p] := upcase(s[p]);
- end;
-
- function getnum(min, max : word) : word;
- {-validate and return number in range min..max}
- var
- num : word;
- code : word;
- begin
- if i = paramcount then
- invalidoption
- else begin
- inc(i);
- arg := stupcase(paramstr(i));
- val(arg, num, code);
- if (code <> 0) or (num < min) or (num > max) then
- invalidoption
- else
- getnum := num;
- end;
- end;
-
- begin
- {no file to speak by default}
- filename := '';
-
- i := 1;
- while i <= paramcount do begin
- arg := stupcase(paramstr(i));
- case arg[1] of
- '/', '-' :
- if length(arg) <> 2 then
- invalidoption
- else
- case arg[2] of
- '?' : writehelp;
- 'I' : pitch := getnum(0, 9);
- 'L' : lpt := getnum(1, 3);
- 'S' : speed := getnum(0, 9);
- 'T' : tone := getnum(0, 1);
- 'V' : volume := getnum(0, 9);
- else
- invalidoption;
- end;
- else
- if filename = '' then
- filename := arg
- else
- invalidoption;
- end;
- inc(i);
- end;
-
- {set the speech options}
- stsetlptport(lpt);
- stsetparams(tone, volume, pitch, speed);
- end;
-
- procedure speakfromkeyboard;
- var
- s : string;
- ps : string;
- begin
- writeln('Enter text to speak. Empty line to quit...');
- repeat
- readln(s);
- if s <> '' then begin
- {convert to phonetic}
- StTextToPhonetic(s, ps);
- writeln(ps);
- stspeak(s);
- end;
- until s = '';
- end;
-
- procedure speakfile(filename : string);
- label
- exitpoint;
- var
- s : string;
- f : text;
-
- function keypressed : boolean;
- {-return True if a key has been pressed}
- Inline(
- $B4/$01/ {mov ah,1}
- $CD/$16/ {int $16}
- $B0/$00/ {mov al,0}
- $74/$02/ {jz nokey}
- $FE/$C0); {inc al}
- {nokey:}
-
- begin
- assign(f, filename);
- reset(f);
- if ioresult <> 0 then begin
- writeln('Unable to open ', filename);
- halt;
- end;
- while not eof(f) do begin
- readln(f, s);
- if ioresult <> 0 then
- goto exitpoint;
- writeln(s);
- stspeak(s);
- if keypressed then
- goto exitpoint;
- end;
- exitpoint:
- close(f);
- if ioresult <> 0 then ;
- end;
-
- begin
- if not stloaded then begin
- writeln('SPEECHVx must be loaded first');
- halt;
- end;
- writeln(modulename, ', Version ', version, ', by TurboPower Software');
- analyzecommandline;
- if filename = '' then
- speakfromkeyboard
- else
- speakfile(filename);
- end.